<template>
  <div>
    <el-row :gutter="15">
      <el-form ref="logisticeCreateForm" :model="logisticeCreateFormData" :rules="rules" size="mini"
        label-width="100px">
        <el-col :span="12">
          <el-form-item label="发货单ID" prop="dispatchListId">
            <el-input v-model="logisticeCreateFormData.dispatchListId" placeholder="请选择发货单ID" readonly
              :disabled='true' :style="{width: '100%'}"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="到达位置" prop="currentAddress">
            <el-input v-model="logisticeCreateFormData.currentAddress" placeholder="请输入到达位置" :maxlength="100"
              show-word-limit clearable :style="{width: '100%'}"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="到达时间" prop="arriveTime">
            <el-date-picker type="datetime" v-model="logisticeCreateFormData.arriveTime"
              format="yyyy-MM-dd HH:mm:ss" value-format="yyyy-MM-dd HH:mm:ss" :style="{width: '100%'}"
              placeholder="请选择到达时间" clearable></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item size="large">
            <el-button type="primary" @click="submitForm">提交</el-button>
            <el-button @click="resetForm">重置</el-button>
          </el-form-item>
        </el-col>
      </el-form>
    </el-row>
    <el-card>
      <div slot="header" class="clearfix">
			  <span>物流信息</span>
		  </div>
      <el-timeline>
      <el-timeline-item
        v-for="(logistice, index) in logisticsList"
        :key="index"
        :timestamp="logistice.arriveTime">
        {{logistice.currentAddress}}
      </el-timeline-item>
    </el-timeline>
    </el-card>
  </div>
</template>
<script>
import {logisticsList, logisticsCreate} from '@/api/storage'
export default {
  components: {},
  props: ['dispatchList'],
  data() {
    return {
      logisticeCreateFormData: {
        dispatchListId: undefined,
        currentAddress: undefined,
        arriveTime: '',
      },
      logisticsList: [],
      rules: {
        dispatchListId: [{
          required: true,
          message: '请选择发货单ID',
          trigger: 'blur'
        }],
        currentAddress: [{
          required: true,
          message: '请输入到达位置',
          trigger: 'blur'
        }],
        arriveTime: [{
          required: true,
          message: '请选择到达时间',
          trigger: 'change'
        }],
      },
    }
  },
  computed: {},
  watch: {
    logistics: function(n, o){
      this.logisticsData = n
    }
  },
  created() {
    this.logisticeCreateFormData.dispatchListId = this.dispatchList.dispatchListId
    this.getLogisticeList()
  },
  mounted() {},
  methods: {
    submitForm() {
      this.$refs['logisticeCreateForm'].validate(valid => {
        if (!valid) return
        logisticsCreate(this.logisticeCreateFormData).then(res => {
          this.getLogisticeList()
        })
      })
    },
    resetForm() {
      this.$refs['logisticeCreateForm'].resetFields()
    },
    // 获取物流列表
    getLogisticeList(){
      logisticsList({dispatchListId: this.dispatchList.dispatchListId}).then(
        res => {
          console.log(res);
          this.logisticsList = res.data.logisticsList
        }
      )
    }
  }
}

</script>
<style>
</style>
